package com.example.administrator.yuejian_2.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.administrator.yuejian_2.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class MainFragment extends Fragment {
<<<<<<< HEAD
=======
    private TextView titleView;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
    private RadioGroup radioGroup;

    private TrainFragment trainFragment;
    private ClubFragment clubFragment;
    private HomeFragment homeFragment;
    private PostFragment postFragment;
    private UserFragment userFragment;

    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;



    public MainFragment() {
        // Required empty public constructor
    }

    public void onViewCreated(View view, @Nullable Bundle saveInstanceState){

<<<<<<< HEAD
=======
        //titleView = (TextView) view.findViewById(R.id.textView_title);
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
        radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup);

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio_train:
<<<<<<< HEAD
=======
                       // titleView.setText("训练");
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
                        trainFragment = new TrainFragment();
                        replaceFragment(trainFragment);
                        break;
                    case R.id.radio_club:
<<<<<<< HEAD
=======
                       // titleView.setText("俱乐部");
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
                        clubFragment = new ClubFragment();
                        replaceFragment(clubFragment);
                        break;
                    case R.id.radio_home:
<<<<<<< HEAD
=======
                       // titleView.setText("约健体育联盟");
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
                        homeFragment = new HomeFragment();
                        replaceFragment(homeFragment);
                        break;
                    case R.id.radio_post:
<<<<<<< HEAD
=======
                        //titleView.setText("晒图");
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
                        postFragment = new PostFragment();
                        replaceFragment(postFragment);
                        break;
                    case R.id.radio_user:
<<<<<<< HEAD
=======
                        //titleView.setText("我的");
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
                        userFragment = new UserFragment();
                        replaceFragment(userFragment);
                        break;
                }
            }
        });
        radioGroup.check(R.id.radio_train);

    }

    private void replaceFragment(Fragment fragment){
<<<<<<< HEAD

=======
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder,fragment);
        fragmentTransaction.commit();

    }






    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        //在Fragment中添加Fragment时，调用getChildFragmentManager获取FragmentManager
        fragmentManager = getChildFragmentManager();

        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

}
